package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.SmallVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    private SmallVideosService videosService;

    @PostMapping
    public ResponseEntity saveVideo(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        videosService.saveVideo(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }

    @GetMapping
    public ResponseEntity videoList(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pageResult = videosService.queryVideoList(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @PostMapping("/{uid}/userFocus")
    public ResponseEntity focusUser(@PathVariable("uid") Long followUserId) {
        videosService.focusUser(followUserId);
        return ResponseEntity.ok(null);
    }

    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity unfocusUser(@PathVariable("uid") Long followUserId) {
        videosService.unfocusUser(followUserId);
        return ResponseEntity.ok(null);
    }

}